package com.dream.service2.Aspect;

import com.dream.service2.annotation.RedissonLock;
import com.dream.service2.lock.DistributedRedisLock;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class RedissonAspect {

    @Around("@annotation(redissonLock)")
    public Object around(ProceedingJoinPoint joinPoint, RedissonLock redissonLock) throws Throwable {
        String key = redissonLock.key();
        DistributedRedisLock.acquire(key);
        System.out.println("加锁成功");
        Object object = joinPoint.proceed();
        DistributedRedisLock.release(key);
        System.out.println("解锁成功");
        return object;
    }
}
